﻿@page "/role"
@inherits AdminCompontentBase

<PageTitle>
    @T("Role")
</PageTitle>

<DefaultCard>
    <AutoHeight>
        <HeaderContent>
            <div class="d-flex mb-6">
                <SSearch @bind-Value="Search" />
                <MSpacer />
                <SButton Small OnClick=OpenAddRoleDialog BorderRadiusClass="rounded-lg">
                    <SIcon Size=18 IsDefaultToolTip="false">@IconConstants.Add</SIcon>
                    <span class="ml-2 btn">@T("Add")</span>
                </SButton>
            </div>
        </HeaderContent>
        <AutoHeightContent>
            <SDataTable Dense
                Height="@("calc(100vh - 288px)")"
                Headers="@_headers"
                Items="Roles"
                TItem="RoleDto"
                ItemsPerPage="PageSize">
                <HeaderColContent Context="header">
                    <span>@header.Text</span>
                </HeaderColContent>
                <ItemColContent>
                    @switch (context.Header.Value)
                    {
                        case nameof(RoleDto.Name):
                            <div class="hover-pointer" @onclick="()=> OpenUpdateRoleDialog(context.Item)">
                                <span>@context.Item.Name</span>
                            </div>
                            break;
                        case nameof(RoleDto.CreationTime):
                            <SDateTimeTitle Value=@context.Item.CreationTime />
                            break;
                        case nameof(RoleDto.ModificationTime):
                            <SDateTimeTitle Value=@context.Item.ModificationTime />
                            break;
                        case (nameof(RoleDto.Creator)):
                            <span>@context.Item.Creator</span>
                            break;
                        case (nameof(RoleDto.Modifier)):
                            <span>@context.Item.Modifier</span>
                            break;
                        case nameof(RoleDto.Enabled):
                            <EnableChip Value="context.Item.Enabled" />
                            break;
                        case "Action":
                            <div class="d-flex">
                                <MButton Icon Class="mr-4" OnClick="()=> OpenUpdateRoleDialog(context.Item)">
                                    <SIcon Tooltip="@T("Edit")">@IconConstants.Update</SIcon>
                                </MButton>
                                <MButton Icon Class="mr-4" OnClick="()=> OpenRemoveRoleDialog(context.Item)">
                                    <SIcon Tooltip="@T("Delete")">@IconConstants.Remove</SIcon>
                                </MButton>
                            </div>
                            break;
                        default:
                            <SItemCol Value="@context.Value"></SItemCol>
                            break;
                    }
                </ItemColContent>
            </SDataTable>
        </AutoHeightContent>
        <FooterContent>
            <SPagination Class="mt-5" @bind-Page="Page" @bind-PageSize=PageSize Total=Total />
        </FooterContent>
    </AutoHeight>
</DefaultCard>

<AddRoleDialog @bind-Visible="AddRoleDialogVisible" OnSubmitSuccess=GetRolesAsync />
<UpdateRoleDialog RoleId=CurrentRoleId @bind-Visible="UpdateRoleDialogVisible" OnSubmitSuccess=GetRolesAsync />